<?php
/**
 * Project  	Newsletter for Joomla 1.5.x
 * Release    	2.0.1
 * @package		Communicator
 * @subpackage	Component
 * @version		$Id$
 * @link 		http://joomlacode.org/gf/project/communicator/
 * @copyright	Copyright (c) 2008 Stefan Granholm, Copyright 2009 Erik Damke - All rights reserved
 * @license		http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 *
 * @Author 		Stefan Granholm (http://www.granholmcms.com), Erik Damke (commqc20@jocoflex.com)
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

class HTML_communicator
{

   function listAll ($menuname, &$rows, $communicator_rights, $pageNav )
   {
      $Itemid     = JRequest::getInt('Itemid');
      $option     = JRequest::getVar('option');
      $showDeleteRow = $communicator_rights['can_delete'];
      $numSubjectSpan = $communicator_rights['can_delete'] ? 2 : 3;
      ?>
<form name="adminForm" action="index.php" method="post">
<table width="100%" cellpadding="4" cellspacing="0" border="0" align="center">
	<tr>
	  <td colspan="4"><?php echo $menuname; ?></td>
	  <td align="right" nowrap="nowrap">
	  <?php echo '&nbsp;&nbsp;&nbsp;'. JText::_('PN_DISPLAY_NR') .'&nbsp;';
		$link = 'index.php?option='.$option.'&Itemid='. $Itemid;
		echo $pageNav->getLimitBox( $link );?></td>
	</tr>	
	<tr>
	  <td colspan="<?php echo $numSubjectSpan; ?>" class="sectiontableheader" width="55%"><?php echo JText::_('E_SUBJECT'); ?></td>
	  <td class="sectiontableheader"><?php echo JText::_('E_START_PUB');?></td>
	  <td align="center" class="sectiontableheader" width="5%" nowrap="nowrap"><?php echo JText::_('HEADER_HITS');?></td>
	<?php if ( $showDeleteRow ) { ?>
	  <td style="width: 32px;" align="center" class="sectiontableheader"><?php echo JText::_('CMN_DELETE');?></td>
	<?php } ?>	  
	</tr>
	<?php
	$k = 0;
	$tabclass = array("sectiontableentry1", "sectiontableentry2");
	foreach ($rows as $row) {
	   $k = $k ? 0 : 1 ;
	   ?>
	<tr class="<?php echo $tabclass[$k]; ?>">
	  <td colspan="<?php echo $numSubjectSpan; ?>"><a href="<?php echo JRoute::_('index.php?option='.$option.'&task=view&Itemid='.$Itemid.'&id='.$row->id); ?>"><?php echo $row->subject; ?></a>
		<?php if( $communicator_rights['is_editor'] ) { ?>
		&nbsp;&nbsp;<a title="<?php echo JText::_('E_EDIT') ?>"
			href="<?php echo JRoute::_('index.php?option='.$option.'&task=edit&Itemid='.$Itemid.'&id='.$row->id); ?>">
	  <img src="<?php echo JURI::base(); ?>images/M_images/edit.png"
			align="middle" border="0" alt="" /></a>
	  <?php }
		if( $communicator_rights['is_sender'] ) { ?>
		&nbsp;&nbsp;<a title="<?php echo JText::_('SEND_BUTTON') ?>"
			href="<?php echo JRoute::_('index.php?option='.$option.'&task=sendNow&Itemid='.$Itemid.'&id='.$row->id); ?>">
	   <img src="<?php echo JURI::base(); ?>media/com_communicator/images/mail_send.png"
			class="mail_send" alt="<?php echo JText::_('SEND_BUTTON') ?>" /></a>
	   <?php } ?></td>
	   <td><?php echo $row->send;?></td>
	   <td align="center"><?php echo $row->hits;?></td>
	   <?php if ( $showDeleteRow ) { ?>
	   <td style="width: 32px;" align="center">
      <form name="deleteForm<?php echo $row->id; ?>"
		    action="<?php echo JRoute::_('index.php?option='.$option); ?>" method="post">
         <input type="hidden" name="id" value="<?php echo $row->id ?>" />
         <input type="hidden" name="task" value="remove" />
			<input type="hidden" name="Itemid" value="<?php echo $Itemid ?>" />
		</form>
		&nbsp;&nbsp;<a title="<?php echo JText::_('CMN_DELETE') ?>"
			href="javascript: if( confirm('<?php echo JText::_('Are you sure you want to delete selected item?'); ?>')) { document.deleteForm<?php echo $row->id;?>.submit(); }">
		<img src="<?php echo JURI::root(); ?>media/com_communicator/images/delete.png" align="middle"
		    border="0" height="22" width="22" alt="<?php echo JText::_('CMN_DELETE');?>"/></a>
	  <?php } ?>	  
	</tr>
	<?php } ?>   
	<tr>
		<td align="center" colspan="5" class="sectiontablefooter">
		<?php
		$link = JRoute::_('index.php?option='.$option.'&Itemid='. $Itemid);
		echo $pageNav->getPagesLinks( $link ); ?>
		</td>
	</tr>
	<tr>
		<td colspan="5" align="center"><?php echo $pageNav->getPagesCounter();?></td>
	</tr>	
</table>
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
</form>
	<?php
   }

   function editNewsletter( &$row, &$publist, $glist )
   {
      global $mainframe;
      $savetext = '';
      $results = $mainframe->triggerEvent( 'onGetEditorContents', array( "html_message", "html_message" ) );
      $editor =& JFactory::getEditor();
      $Itemid = JRequest::getInt('Itemid');
      $option = JRequest::getVar('option');
      foreach ($results as $result) {
         if (trim($result)) {
            $savetext .= $result;
         }
      }
      // Add the Calendar includes to the document <head> section
      JHTML::_('behavior.calendar');
      ?>
<script language="javascript" type="text/javascript">
	function cmc_submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
		   submitform( pressbutton );
			return true;
		}

		// do field validation
		try {
			document.adminForm.onsubmit();
			}
		catch(e){}
			if (form.subject.value == '') {
				alert('<?php echo JText::_('CM_NEWSLETTER_MUST_HAVE_SUBJECT',true); ?>');
			}
			else {
				<?php echo $savetext; ?>
				submitform( pressbutton );
			}
	}
</script>
<table cellspacing="0" cellpadding="0" border="0" width="100%">
	<tr>
	   <td class="contentheading"><?php echo $row->id ? JText::_('E_EDIT') : JText::_('E_ADD'); echo ": ".JText::_('CM_NEWSLETTER_ITEM'); ?></td>
	   <td><a href="#" onclick="javascript: cmc_submitbutton('save')">
         <img name="new" src="<?php echo JURI::base(); ?>administrator/images/save_f2.png"
			height="32" width="32" border="0" /> <?php echo JText::_('E_SAVE'); ?></a>
      </td>
		<td>&nbsp;</td>
		<td width="25%"><a href="#" onclick="javascript: cmc_submitbutton('cancel')">
		    <img name="new" src="<?php echo JURI::base(); ?>administrator/images/cancel_f2.png"
			height="32" width="32" border="0" /> <?php echo JText::_('E_CANCEL'); ?></a>
		</td>
	</tr>
</table>
<br />
<br />

<form action="index.php" method="post" name="adminForm">

<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminform">
   <tr>
	  <td width="200">
	  <div style="font-weight: bold; text-align: right"><?php echo JText::_('E_SUBJECT'); ?></div>
	  </td>
	  <td><input class="inputbox" type="text" name="subject" size="25"
			value="<?php echo $row->subject; ?>" style="width: 500px"></td>
	</tr>
	<tr>
		<td valign="top">
	   <div style="font-weight: bold; text-align: right"><?php echo JText::_('CM_MSG_HTML'); ?>:</div>
		<br /><?php echo JText::_('CM_NAME_TAG_USAGE'); ?>
	   </td>
		<td><?php
		echo $editor->display( "html_message", str_replace('&','&amp;',stripcslashes($row->html_message)), 500, 300, 70, 20 );
		?></td>
	</tr>
	<tr>
		<td valign="top">
		<div style="font-weight: bold; text-align: right"><?php echo JText::_('CM_TEXT_MSG'); ?>:</div>		
		<br /><?php echo JText::_('CM_NAME_TAG_USAGE'); ?>
		</td>
		<td><textarea name="message" cols="70" rows="20" style="width: 500px; height: 300px;">
		    <?php echo str_replace('&','&amp;',stripcslashes($row->message)); ?>
		    </textarea>
		</td>
	</tr>
	<tr>
		<td valign="top">
   	<div style="font-weight: bold; text-align: right"><?php echo JText::_('CMN_PUBLISHED'); ?>:</div>
		</td>
		<td><?php echo $publist; ?></td>
	</tr>
	<tr>
		<td>
      <div style="font-weight: bold; text-align: right"><?php echo JText::_('E_STATE'); ?></div>
		</td>
		<td><?php echo ($row->published=='1') ? JText::_('CMN_PUBLISHED') : JText::_('CMN_UNPUBLISHED');	?></td>
	</tr>
	<tr>
		<td>
	   <div style="font-weight: bold; text-align: right"><?php echo JText::_('E_ACCESS_LEVEL'); ?></div>
		</td>
		<td><?php echo $glist; ?></td>
	</tr>
	<tr>
		<td>
		<div style="font-weight: bold; text-align: right"><?php echo JText::_('E_START_PUB'); ?></div>
		</td>
		<td><?php echo JHTML::_('calendar', $row->publish_up, 'publish_up', 'publish_up', '%Y-%m-%d %H:%M:%S', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?></td>
	</tr>
	<tr>
		<td>
		<div style="font-weight: bold; text-align: right"><?php echo JText::_('E_FINISH_PUB'); ?></div>
		</td>
		<td><?php echo JHTML::_('calendar', $row->publish_down, 'publish_down', 'publish_down', '%Y-%m-%d %H:%M:%S', array('class'=>'inputbox', 'size'=>'25',  'maxlength'=>'19')); ?></td>
	</tr>
</table>

	<?php if (!$row->id) { ?>
	<input type="hidden" name="created" value="<?php echo date('Y-m-d H:i:s'); ?>" />
	<?php } else { ?>
	<input type="hidden" name="id" value="<?php echo $row->id; ?>" /> <?php } ?>
	<input type="hidden" name="task" value="">
	<input type="hidden" name="option" value="<?php echo $option; ?>" />
	<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
</form>
<?php
   }

   function viewNewsletter( $row )
   {
      global $cm_params;
      $editionDate =& JFactory::getDate($row->created);
      $editionDateFormat= $cm_params->get( 'edition_date_format', '%Y-%m-%d %H:%M:%S' );
      ?>
<div class="componentheading"><?php echo JText::_('CM_NEWSLETTER_ITEM'); ?>
<!-- removed with V2.0.1
<a href="javascript: history.back()">&nbsp;<?php echo JText::_('BACK'); ?></a>
-->
</div>
<div align="right" class="createdate"><?php echo sprintf( JText::_('CM_EDITION_OF'), $editionDate->toFormat($editionDateFormat) ); ?></div>
<div><strong><?php echo $row->title; ?></strong></div>
<br />
<div><?php echo stripcslashes($row->text); ?></div>
<?php
   }

   function sendNewsletter( &$row, $grouplist, $fromMail, $fromName, $replyMail )
   {
      global $cm_params;

      $Itemid = JRequest::getInt('Itemid');
      $option = JRequest::getVar('option');
      ?>
<div id="overDiv" style="position: absolute; visibility: hidden; z-index: 1000;"></div>
<script language="Javascript" src="includes/js/overlib_mini.js"></script>
<table cellpadding="4" cellspacing="0" border="0" width="100%">
	<tr>
		<td class="contentheading"><?php echo JText::_('CM_SEND_NEWSLETTER'); ?></td>
	</tr>
</table>
<form action="index.php" method="post" name="adminForm">
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminform">
	<tr>
		<td width="250"><strong><?php echo JText::_('CM_SEND_TO_GROUP'); ?>:</strong></td>
		<td width="85%"><?php echo $grouplist; ?></td>
	</tr>
	<tr>
		<td width="250"><strong><?php echo JText::_('CM_CONFIRMED_ACCOUNTS_ONLY'); ?></strong></td>
		<td width="85%"><input type="checkbox" name="confirmed_accounts"
			value="1"> <?php echo JHTML::_('tooltip', JText::_('CM_CONFIRMED_ACCOUNTS_ONLY_TIP') ); ?></td>
	</tr>
	<tr>
		<td><strong><?php echo JText::_('CM_MAIL_FROM'); ?>:</strong></td>
		<td><input class="inputbox" type="text" name="mailfrom" size="25"
			value="<?php echo $fromMail; ?>" style="width: 200px"></td>
	</tr>
	<tr>
      <td><strong><?php echo JText::_('CM_SENDER_FROM'); ?>:</strong></td>
      <td><input class="inputbox" type="text" name="namefrom" size="25"
         value="<?php echo $fromName; ?>" style="width: 200px"></td>
   </tr>
	<tr>
		<td><strong><?php echo JText::_('CM_REPLY_TO'); ?>:</strong></td>
		<td><input class="inputbox" type="text" name="replyto" size="25"
			value="<?php echo $replyMail; ?>" style="width: 200px"></td>
	</tr>
	<tr>
		<td width="250"><strong><?php echo JText::_('CM_DISABLE_TIMEOUT'); ?>:</strong></td>
		<td width="85%"><input type="checkbox" checked="checked"
			name="disable_timeout" value="1"> <?php echo JHTML::_('tooltip', JText::_('Disable timeout tip') ); ?></td>
	</tr>
	<?php
	if( strstr( $row->html_message, '[NAME]') === false && strstr( $row->message, '[NAME]') === false) {
	   $mails_per_pageload= $cm_params->get( 'normal_mails_per_pageload', 500 );
	}
	else {
	   $mails_per_pageload = $cm_params->get('personalized_mails_per_pageload' , 100 );
	}
	?>
   <tr>
	  <td style="text-align: right;" width="250">
		 <label for="mails_per_pageload"><strong><?php echo JText::_('CM_MAILS_PER_STEP'); ?>:</strong></label>
	  </td>
	  <td width="85%">
	     <input type="text" id="mails_per_pageload" name="mails_per_pageload" value="<?php echo $mails_per_pageload; ?>"/>
     </td>
	</tr>
	<tr>
	  <td colspan="2"><hr /></td>
	</tr>
	<tr>
	  <td><strong><?php echo JText::_('E_SUBJECT'); ?></strong></td>
	  <td><?php echo $row->subject; ?></td>
	</tr>
	<tr>
	  <td valign="top"><strong><?php echo JText::_('CM_MSG_HTML'); ?>:</strong></td>
	  <td valign="top"><?php echo stripcslashes($row->html_message); ?></td>
	</tr>
	<tr>
	  <td valign="top"><strong><?php echo JText::_('CM_MSG'); ?>:</strong></td>
	  <td valign="top"><?php echo stripcslashes(htmlspecialchars($row->html_message)); ?></td>
	</tr>
	<tr>
	  <td valign="top"><strong><?php echo JText::_('CM_TEXT_MSG'); ?>:</strong></td>
	  <td valign="top"><?php echo stripcslashes(htmlspecialchars($row->message)); ?></td>
	</tr>
</table>

<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
</form>
	<?php
   }

   function sendMailInfo( $all_rows, $startfrom, $msg )
   {
      $config     =& JFactory::getConfig();
      $mails_per_pageload  = JRequest::getInt( 'mails_per_pageload', 100 );
      $option     = JRequest::getVar( 'option', 'com_communicator' );
      $disable_timeout  = JRequest::getVar( 'disable_timeout', '' );
      $id         = JRequest::getVar( 'id', '' );
      $sendto     = JRequest::getVar( 'sendto', null );
      $mailfrom   = JRequest::getVar( 'mailfrom', $config->getValue('config.mailfrom') );
      $namefrom   = JRequest::getVar( 'namefrom', $config->getValue('config.fromname') );
      $confirmed_accounts = JRequest::getVar( 'confirmed_accounts', '0' );
      $replyto    = JRequest::getVar( 'replyto', false );

      echo '<h3>'.JText::_('CM_SEND_LOG').'</h3>
		<pre>'. $msg .'</pre>
		<p><strong>'.sprintf( JText::_('CM_NUMBER_OF_MAILS_SENT'), $startfrom , $all_rows ).'<strong></p>
		<p>'.sprintf( JText::_('CM_SEND_NEXT_X_MAILS'), $mails_per_pageload ) .'</p>
		<br /><br />
		<form action="index.php" method="post" name="adminForm">'.
      JText::_('CM_CHANGE_MAILS_PER_STEP').':'.
		'<input type="text" name="mails_per_pageload" value="'. $mails_per_pageload .'" size="4" />
		<br /><br />'.
		'<input type="hidden" name="startfrom" value="'. $startfrom .'" />
		<input type="hidden" name="disable_timeout" value="'. $disable_timeout .'" />
		<input type="hidden" name="id" value="'. $id .'" />
		<input type="hidden" name="sendto" value="'. $sendto .'" />
		<input type="hidden" name="mailfrom" value="'. $mailfrom .'" />
		<input type="hidden" name="namefrom" value="'. $namefrom .'" />
		<input type="hidden" name="confirmed_accounts" value="'. $confirmed_accounts .'" />
		<input type="hidden" name="replyto" value="'. $replyto .'" />
		<input type="hidden" name="task" value="sendMail" />
		<input type="hidden" name="option" value="'.$option.'" />
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input style="font-weight:bold;" type="submit" name="send" value="&nbsp;&nbsp;&nbsp;&nbsp;'. JText::_('SEND_BUTTON') .'&nbsp;&nbsp;&nbsp;&nbsp;" />
			&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="button" name="abort" value="'. JText::_('E_CANCEL') .'" onclick="if( confirm( \''.JText::_('CM_CONFIRM_ABORT_SENDING').'\' )) { document.location=\'index.php?option='.$option.'\'; }" />
	</form>
	<br /><br />';
   }

   function subscribeSubscriber( )
   {
      global $mainframe;
      $database=& JFactory::getDBO();
      $Itemid  = JRequest::getInt('Itemid');
      $option  = JRequest::getVar('option');      
      $user    =& JFactory::getUser();
      $check 	= 'SELECT id FROM `#__users`, `#__communicator_subscribers`'.
					' WHERE user_id=id'.
					' AND user_id='.$user->id;
      $database->setQuery( $check );
      $result = $database->loadObject();

      $name 	= addslashes(JRequest::getVar('subscriber_name','Subscriber' ));
      $email 	= addslashes(JRequest::getVar('subscriber_email'));
      
      if( !$result )
         {
         if(!empty($email)){
            saveSubscriber( $name, $email );
         }
         else {
            //new subscriber
            HTML_communicator::showField('subscribe');
         }
      }
      
   }

   function unsubscribeSubscriber( )
   {
      global $mainframe;
      $database=& JFactory::getDBO();
      $Itemid  = JRequest::getInt('Itemid');
      $option  = JRequest::getVar('option');      
      $user    =& JFactory::getUser();
      $name 	= addslashes(JRequest::getVar('subscriber_name'));
      $email 	= addslashes(JRequest::getVar('subscriber_email'));

      if( !empty($email) ) {
         $check = 'SELECT subscriber_name'.
						' FROM `#__communicator_subscribers`'.
						' WHERE subscriber_email='.$database->Quote($email);
         $database->setQuery( $check );
         $result = $database->loadObject();
         if( $result ) {
            //delete
            deleteSubscriber( $result->subscriber_name, $email );
         }
         else {
            $mainframe->redirect( 'index.php?option='.$option.'&Itemid='.$Itemid,
               JText::_('CM_EMAIL_NOT_FOUND') );
         }
      }
      else{
         //new subscriber
         HTML_communicator::showField('unsubscribe');
      }

   }

   function showField( $action )
   {      
      $database=& JFactory::getDBO();
      $Itemid  = JRequest::getInt('Itemid');
      $option  = JRequest::getVar('option');
      $user    =& JFactory::getUser();

      if( $user->id ) {
         if( $action == 'subscribe') {
            $query='SELECT name as subscriber_name, email as subscriber_email'.
						' FROM `#__users`'.
						' WHERE id ='.$user->id;
            $database->setQuery($query);
            $subscriberdata = $database->loadObject();
         }
         elseif( $action == 'unsubscribe') {
            $query='SELECT subscriber_name, subscriber_email'.
						' FROM `#__communicator_subscribers`'.
						' WHERE user_id='.$user->id;
            $database->setQuery($query);
            $subscriberdata = $database->loadObject();
         }
      }
      if( empty($subscriberdata)) {
         $subscriberdata =& new stdClass();
         $subscriberdata->subscriber_email = '';
         $subscriberdata->subscriber_name = '';
      }

      // default values
      $show_name_field = 1;
      $max_name_length = 15;
      $module = &JModuleHelper::getModule('communicatorsubscribe');
      if( is_object($module) && $module->id ) 
         {
         $params = new JParameter($module->params, JPATH_SITE . '/modules/mod_communicatorsubscribe/mod_communicatorsubscribe.xml');
         $show_name_field = $params->get( 'show_name_field', $show_name_field );
         $max_name_length = intval( $params->get( 'name_max_length', $max_name_length) );          
         }
      $action_lbl = ($action=='subscribe') ? JText::_('CM_SUBSCRIBE') : JText::_('CM_UNSUBSCRIBE');
      ?>
<script language="javascript" type="text/javascript">
function cm_validate() {
   var max_length = <?php echo $max_name_length; ?>;
   if ( <?php if( $show_name_field == '1'){ ?> document.showField.subscriber_name.value == "" || <?php } ?> document.showField.subscriber_email.value == "") {
      alert('<?php echo JText::_('CM_PLEASE_COMPLETE_ALL_FIELDS',true); ?>');
      return false;}
  	<?php if( $show_name_field == '1' && $max_name_length > 0){ ?>
   if (document.showField.subscriber_name.length > max_length) {
      alert("<?php echo JText::_('CM_FORM_SHORTERNAME',true); ?>");
      return false;}
  	<?php } ?>  
   return true;
   }
</script>
<form method="post" name="showField" action="index.php">
<table border="0" cellpadding="0" cellspacing="0" class="contentpane" width="100%">
	<tr>
	  <th align="left" colspan="2"><?php echo JText::_('CM_YOUR_DETAILS'); ?></th>
	  <th width="40%"><br /><br /></th>
	</tr>
	<?php if($show_name_field=='1'){ ?>
	<tr>
	  <td><?php echo JText::_('REGISTER_NAME'); ?></td>
	  <td><input type="text" name="subscriber_name" size="32" class="inputbox" maxlength="64"
		    <?php if ($action=='unsubscribe' && !empty($subscriberdata->subscriber_name)){echo 'readonly="readonly"';}; ?>
            value="<?php echo $subscriberdata->subscriber_name; ?>"/></td>
	  <td><br /><br /></td>
	</tr>
	<?php } ?>
	<tr>
	  <td><?php echo JText::_('PROMPT_EMAIL'); ?></td>
	  <td><input type="text" name="subscriber_email" size="32" class="inputbox" maxlength="64"
		    <?php if ($action=='unsubscribe' && !empty($subscriberdata->subscriber_name)){echo 'readonly="readonly"';}; ?>
			value="<?php echo $subscriberdata->subscriber_email; ?>"></td>
	  <td><br /><br /></td>
	</tr>
	<tr>
	  <td colspan="2"><br />
	  <input type="submit" name="submit" value="<?php echo $action_lbl; ?>"
			class="button" onclick="return cm_validate();" /></td>
	  <td></td>
	</tr>
</table>
	<?php // Insert hidden namefield
	if ($show_name_field!='1'){ ?>
	  <input type="hidden" name="subscriber_name" class="inputbox" maxlength="64"
	  <?php if ($action=='unsubscribe' && !empty($subscriberdata->subscriber_name)){echo 'readonly="readonly"';}; ?>
	        value="<?php echo $subscriberdata->subscriber_name; ?>">
	<?php }
	// used for spoof hardening
	$validate = cm_SpoofValue(1); ?>
	  <input type="hidden" name="task" value="<?php echo $action; ?>" />
	  <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
	  <input type="hidden" name="option" value="<?php echo $option; ?>" />
	  <input type="hidden" name="<?php echo $validate; ?>" value="1" />
</form>
<?php
   }
   
   function header() 
   {}
   	
   function defaultHeaderOpen() 
   {
      global $cm_params;      
      ?>   	
<table class="contentpaneopen<?php echo htmlspecialchars($cm_params->get( 'pageclass_sfx' )); ?>">
<tr valign="top">
<?php if ($cm_params->get('show_page_title') ) : ?>   
   <td class="contentheading<?php echo htmlspecialchars($cm_params->get( 'pageclass_sfx' )); ?>" width="70%">
     <?php echo htmlspecialchars($cm_params->get('page_title')); ?>     
   </td>   
<?php endif;    	
   }
      
   function defaultHeaderClose() 
   {
   ?></tr>
   </table>
   <?php
   }
   
   function footer() {
      $CmVersion = new CM_comVersion();
      echo '<br /><b>Thanks for your subscribing. A letter of confirmation will be sent to your email for activation. </b>'
     
      . JText::_('').' '
      ;
   }

   function new_bar()
   {
      $Itemid = JRequest::getInt('Itemid');
      $option = JRequest::getVar('option');
      require_once( JPATH_SITE."/includes/HTML_toolbar.php");
?>
<td width="25" align="right">
   <a href="<?php echo JRoute::_( 'index.php?option='.$option.'&task=edit&Itemid='.$Itemid); ?>">
   <img name="new" src="<?php echo JURI::base(); ?>administrator/images/new_f2.png"
	height="32" width="32" border="0" /> <?php echo JText::_('CMN_NEW'); ?></a>
</td>
<?php
   }

   function send_bar()
   {
      require_once( JPATH_SITE.'/includes/HTML_toolbar.php');
      ?>
<script language="javascript" type="text/javascript">
   function submitbutton(pressbutton) {
	var form = document.adminForm;
	if (pressbutton == 'cancel') {submitform( pressbutton ); return; }
   // do field validation
   if (getSelectedValue('adminForm','sendto') < 0) {
		alert( "<?php echo JText::_('CM_SELECT_A_GROUP',true) ?>" );
		} else if (confirm ("<?php echo JText::_('CM_WARNING_SEND_NEWSLETTER',true) ?>")) {
		  submitform( 'sendMail' ); } 
	}
</script>

<td width="50%" align="right"><a href="javascript:submitbutton('sendMail');">
   <img name="publish" src="<?php echo JURI::base(); ?>/administrator/images/publish_f2.png"
      align="middle" height="32" width="32" border="0" /> <br />
      <?php echo JText::_('SEND_BUTTON'); ?> </a>&nbsp;
</td>
<td width="50%" align="left">&nbsp; <a href="javascript:submitbutton('cancel');">
   <img name="back" src="<?php echo JURI::base(); ?>/administrator/images/back_f2.png"
	   align="middle" height="32" width="32" border="0" /> <br />
      <?php echo JText::_('CMN_CANCEL'); ?> </a>
</td>
<?php
   }

   function subscriber_bar()
   {
      $database=& JFactory::getDBO();
      $Itemid  = JRequest::getInt('Itemid');
      $option  = JRequest::getVar('option');
      $user    =& JFactory::getUser();
      $subscriber = null;
      if( $user->id ) {
         $database->setQuery('SELECT user_id FROM `#__communicator_subscribers`'.
						' WHERE user_id='.$user->id.
						' OR subscriber_email =\''.$user->email.'\'');
         $subscriber = $database->loadObject();
      }
      ?>
<table align="center">
	<tr>
	<?php
	if(!$subscriber) {
	   ?>
		<td><img src="<?php echo JURI::base(); ?>media/com_communicator/images/subscribe.png"
			alt="<?php echo JText::_('CM_SUBSCRIBE'); ?>" align="middle" border="0" />
			<a href="<?php echo JRoute::_( 'index.php?option='.$option.'&task=subscribe&Itemid='.$Itemid); ?>"
			   title="<?php echo JText::_('CM_SUBSCRIBE'); ?>"> &nbsp;<?php echo JText::_('CM_SUBSCRIBE_TO'); ?>
			</a>
		</td>
		<?php
	}
	else {
		?>
		<td>&nbsp;&nbsp; <img src="<?php echo JURI::base(); ?>media/com_communicator/images/unsubscribe.png"
			alt="<?php echo JText::_('CM_UNSUBSCRIBE'); ?>" align="middle" border="0" />
			<a href="<?php echo JRoute::_( 'index.php?option='.$option.'&task=unsubscribe&Itemid='.$Itemid); ?>"
			   title="<?php echo JText::_('CM_UNSUBSCRIBE'); ?>"> &nbsp;<?php echo JText::_('CM_UNSUBSCRIBE_FROM'); ?>
			</a>
		</td>
		<?php
	}
	?>
	</tr>
</table>
<?php
	}
}